home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / init.d / apparmor < prev    next >
Text File  |  2009-10-17  |  3KB  |  124 lines

  1. #!/bin/sh
  2. # ----------------------------------------------------------------------
  3. #    Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  4. #     NOVELL (All rights reserved)
  5. #    Copyright (c) 2008, 2009 Canonical, Ltd.
  6. #
  7. #    This program is free software; you can redistribute it and/or
  8. #    modify it under the terms of version 2 of the GNU General Public
  9. #    License published by the Free Software Foundation.
  10. #
  11. #    This program is distributed in the hope that it will be useful,
  12. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #    GNU General Public License for more details.
  15. #
  16. #    You should have received a copy of the GNU General Public License
  17. #    along with this program; if not, contact Novell, Inc.
  18. # ----------------------------------------------------------------------
  19. # Authors:
  20. #  Steve Beattie <steve.beattie@canonical.com>
  21. #  Kees Cook <kees@ubuntu.com>
  22. #
  23. # /etc/init.d/apparmor
  24. #
  25. ### BEGIN INIT INFO
  26. # Provides: apparmor
  27. # Required-Start: mountall
  28. # Required-Stop: umountfs
  29. # Default-Start: S
  30. # Default-Stop:
  31. # Short-Description: AppArmor initialization
  32. # Description: AppArmor init script. This script loads all AppArmor profiles.
  33. ### END INIT INFO
  34.  
  35. . /etc/apparmor/functions
  36. . /lib/lsb/init-functions
  37.  
  38. usage() {
  39.     echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
  40. }
  41.  
  42. test -x ${PARSER} || exit 0 # by debian policy
  43. # LSM is built-in, so it is either there or not enabled for this boot
  44. test -d /sys/module/apparmor || exit 0
  45.  
  46. securityfs() {
  47.     # Need securityfs for any mode
  48.     if [ ! -d "${AA_SFS}" ]; then
  49.         if cut -d" " -f2,3 /proc/mounts | grep -q "^${SECURITYFS} securityfs"'$' ; then
  50.             log_action_msg "AppArmor not available as kernel LSM."
  51.             log_end_msg 1
  52.             exit 1
  53.         else
  54.             log_action_begin_msg "Mounting securityfs on ${SECURITYFS}"
  55.             if ! mount -t securityfs none "${SECURITYFS}"; then
  56.                 log_action_end_msg 1
  57.                 log_end_msg 1
  58.                 exit 1
  59.             fi
  60.         fi
  61.     fi
  62.     if [ ! -w "$AA_SFS"/.load ]; then
  63.         log_action_msg "Insufficient privileges to change profiles."
  64.         log_end_msg 1
  65.         exit 1
  66.     fi
  67. }
  68.  
  69. case "$1" in
  70.     start)
  71.         log_daemon_msg "Starting AppArmor profiles"
  72.         securityfs
  73.         load_configured_profiles
  74.         rc=$?
  75.         log_end_msg "$rc"
  76.         ;;
  77.     stop)
  78.         log_daemon_msg "Unloading AppArmor profiles"
  79.         securityfs
  80.         running_profile_names | while read profile; do
  81.             if ! unload_profile "$profile" ; then
  82.                 log_end_msg 1
  83.                 exit 1
  84.             fi
  85.         done
  86.         rc=0
  87.         log_end_msg $rc
  88.         ;;
  89.     restart|reload|force-reload)
  90.         log_daemon_msg "Reloading AppArmor profiles"
  91.         securityfs
  92.         clear_cache
  93.         load_configured_profiles
  94.         rc=$?
  95.  
  96.         # Now, we have to find profiles that were removed.  Currently
  97.         # we must re-parse all the profiles to get policy names.  :(
  98.         aa_configured=$(mktemp -t aa-XXXXXX)
  99.         configured_profile_names > "$aa_configured" || exit 1
  100.         aa_loaded=$(mktemp -t aa-XXXXXX)
  101.         running_profile_names > "$aa_loaded" || exit 1
  102.         comm -2 -3 "$aa_loaded" "$aa_configured" | while read profile ; do
  103.             unload_profile "$profile"
  104.             done
  105.         rm -f "$aa_configured" "$aa_loaded"
  106.  
  107.         log_end_msg "$rc"
  108.         ;;
  109.     status)
  110.         securityfs
  111.         if [ -x /usr/bin/aa-status ]; then
  112.             /usr/bin/aa-status --verbose
  113.         else
  114.             cat "$AA_SFS"/profiles
  115.         fi
  116.         rc=$?
  117.         ;;
  118.     *)
  119.         usage
  120.         exit 1
  121.         ;;
  122.     esac
  123. exit $rc
  124.